package dse.messages.multiversion;

import dse.DataObject;
import dse.DataShare;
import dse.Experiment;
import dse.ExperimentRecorder;
import dse.Version;
import dse.messages.Message;
import dse.messages.MessageHandler;
import dse.messages.MessageSender;
import dse.messages.MessageType;

public class SVRMessageHandler extends MessageSender implements MessageHandler {
	private DataObject dobj;
	private Version version;
	
	public SVRMessageHandler(Experiment experiment, DataObject dobj, Version version)
	{
		super(experiment);
		this.dobj = dobj;
		this.version = version;
	}
	
	@Override
	public boolean acceptMessage(Message message) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void messageInterupted(ExperimentRecorder recorder, Message message,
			double timeLeft) {
		// TODO Auto-generated method stub
		;
	}

	@Override
	public void messageReceived(ExperimentRecorder recorder, Message message,
			double timeLeft) {
		// TODO Auto-generated method stub
		recorder.debug(this, "msgRcvd: " + message, timeLeft);
		if (message.messageType() != MessageType.SVR) {
			recorder.warn(
					"SVRMessageHandler recieved " + 
					message.messageType() + " message."
					);
			return;
		}
		
		DataShare share = message.to().getDataShare(dobj);
		if(share != null)
			share.SVRTLO(version);
	}
}
